﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EdexApiClient
{
    public partial class EdexApiContext
    {
        public void AccessToCompany()
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {
                var uri = System.IO.Path.Combine(this.RootUri, "security/AccessToCompany/?api_key={0}");
                var result = client.GetAsync(String.Format(uri, this.session.APIKEY)).Result;

                if (result.StatusCode != System.Net.HttpStatusCode.OK)
                    throw new Exception(result.Content.ReadAsStringAsync().Result);
            }
        }

        public void AccessToCompanyUseKey(string code)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {
                var uri = System.IO.Path.Combine(this.RootUri, "security/AccessToCompanyUseKey/?api_key={0}&code={1}");
                var result = client.GetAsync(String.Format(uri, this.session.APIKEY, code)).Result;

                if (result.StatusCode != System.Net.HttpStatusCode.OK)
                    throw new Exception(result.Content.ReadAsStringAsync().Result);
            }
        }

        public void AccessToCompanyConfirm(string id)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {
                var uri = System.IO.Path.Combine(this.RootUri, "security/AccessToCompanyConfirm/?api_key={0}&id={1}");
                var result = client.GetAsync(String.Format(uri, this.session.APIKEY, id.ToString())).Result;

                if (result.StatusCode != System.Net.HttpStatusCode.OK)
                    throw new Exception(result.Content.ReadAsStringAsync().Result);
            }
        }


    }
}